/*************************************************************************
	> File Name: EnumTranslate.java
	> Author:Blackwall 
	> Mail:wangzq@besti.edu.cn 
	> Created Time: 2018年03月28日 星期三 23时34分41秒
 ************************************************************************/
import java.util.Scanner;
import java.util.InputMismatchException;

public class NumTranslate{
    public static void main(String []agrs){
        int j = 0, num = 0;
        int temp[] = new int[7];
        boolean flag = true;

        System.out.println("The program starts!");
        System.out.println("Please input a Integer in the following range : [-100000, 100000]");
        Scanner scan = new Scanner(System.in);
        do{
            try{
                num = Integer.parseInt(scan.nextLine());
                flag = false;
            }catch(Exception e){
                System.out.println("Catch a Exception:"+ e);
                System.out.println("Please input again!");
                flag =true;
            }
        }while(flag == true);

        while(num > 100000 || num < -100000){
            System.out.println("The input number is out of range! Please reinput again!");
            num = scan.nextInt();
        }
        System.out.println("The translation of the number entered above :");
        if(num < 0){
            System.out.print("fu ");
            num = Math.abs(num);
        }
        while(num > 0){
            temp[j]= num % 10;
            num = num /10;
            j++;
        }
        for(j--;j>=0; j--){
            switch(temp[j]){
                case 0:
                    System.out.print("ling ");
                    break;
                case 1:
                    System.out.print("yi ");
                    break;
                case 2:
                    System.out.print("er ");
                    break;
                case 3:
                    System.out.print("san ");
                    break;
                case 4:
                    System.out.print("si ");
                    break;
                case 5:
                    System.out.print("wu ");
                    break;
                case 6:
                    System.out.print("liu ");
                    break;
                case 7:
                    System.out.print("qi ");
                    break;
                case 8:
                    System.out.print("ba ");
                    break;
                case 9:
                    System.out.print("jiu ");
                    break;
            } 
        }
        System.out.print("\b");//eliminate the last space.
        System.out.print("\nThe program exits!\n");
    }
}

